/*
 * @Author: your name
 * @Date: 2021-07-02 09:37:37
 * @LastEditTime: 2021-07-02 10:59:13
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Skip\assets\script\RankingItem.ts
 */
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class RankingItem extends cc.Component {
    // 玩家昵称
    @property(cc.Label)
    nickname: cc.Label = null;
    // 玩家排名
    @property(cc.Label)
    rinkNum: cc.Label = null;
    // 分数
    @property(cc.Label)
    score: cc.Label = null;

    // 排行榜单个背景
    @property(cc.SpriteFrame)
    rinking_light_bg: cc.SpriteFrame = null;

    // 排行榜单个背景
    @property(cc.Sprite)
    avatar: cc.Sprite = null;

    // 图集资源
    @property(cc.SpriteAtlas)
    avatars: cc.SpriteAtlas = null


    // LIFE-CYCLE CALLBACKS:

    onLoad() {

    }

    init(nickname: string, rinkNum: string, score: string, avatar: string) {
        this.nickname.string = nickname;
        this.rinkNum.string = rinkNum;
        this.score.string = score;
        if (parseInt(rinkNum) % 2 !== 0) {
            this.node.getComponent(cc.Sprite).spriteFrame = this.rinking_light_bg;
        }
        // 修改头像，获取图集
        this.avatar.spriteFrame = this.avatars.getSpriteFrame(`tou_${parseInt(avatar) - 1}`)
    }

    start() {

    }

    // update (dt) {}
}
